"""
匿名函数，lambda表达式, 一般用于比较简单的函数
lambda 参数: 表达式
"""

add = lambda x, y : x +y
"""
add 指向 匿名函数
"""

# 调用匿名函数
sum = add(11, 22)
print(sum)

# 使用lambda表达式对列表排序
infos = [{"name":"wxh","age":18}, {"name":"lqh","age":34}, {"name":"zyq","age":22}, {"name":"xdw","age":40}]
infos.sort(key = lambda x : x["name"])
print(infos)
infos.sort(key = lambda x : x["age"])
print(infos)


def calculate(a, b, func):
    """
    func 为lambda函数
    calculate(10,20, lambda表达式)
    """
    result = func(a, b)
    print(result)

calculate(10, 20, lambda a, b : a + b)
calculate(10, 20, lambda a, b : a - b)
calculate(10, 20, lambda a, b : a * b)
calculate(10, 20, lambda a, b : a / b)